﻿using KFM.Services.Base;
using Services.IService;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Services.Service
{
    public class AnimalService : BaseService,IAnimalService
    {
        static CancellationTokenSource cancellationToken = new CancellationTokenSource();
        public void Work()
        {
            Console.WriteLine("88880000");
            var test = 0;
            Thread thread = new Thread(() => { Test02(); });
            thread.Start();
            Thread thread2 = new Thread(() => { Test02(); });
            thread2.Start();    
            Console.WriteLine("请按回车键停止多线程");
            //var IsCancel = Console.ReadLine();
            //if (IsCancel == "1")
            //{
            //    cancellationToken.Cancel();
            //    Console.WriteLine("线程挂起来了!");
            //}
            //else {
            //    Console.WriteLine("线程继续运行了!");
            //}
            //var IsCancel2 = Console.ReadLine();
            //if (IsCancel2 == "1")
            //{
            //    Console.WriteLine("线程挂起来了!");
            //}
            //else
            //{
            //    Console.WriteLine("线程继续运行了!");
            //    cancellationToken = new CancellationTokenSource();
            //    thread2.Start();
            //}
            Console.ReadLine();
        }
        static void Test()
        {
            while (true)
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    Console.WriteLine($"DateTime:{DateTime.Now}");
                    Thread.Sleep(1000);
                }
                break;
            }
        }
        static void Test02()
        {
            for (var i = 0; i <= 1000; i++)
            {
                Console.WriteLine($"子线程ID：{Thread.CurrentThread.ManagedThreadId}------{i}");
                Thread.Sleep(1000); 
            }
        }
    }
}
